package cn.stylefeng.guns.modular.transport.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.transport.entity.TransportCost;
import cn.stylefeng.guns.modular.transport.mapper.TransportCostMapper;
import cn.stylefeng.guns.modular.transport.model.params.TransportCostParam;
import cn.stylefeng.guns.modular.transport.model.result.TransportCostResult;
import  cn.stylefeng.guns.modular.transport.service.TransportCostService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * 运输费用表 服务实现类
 */
@Service
public class TransportCostServiceImpl extends ServiceImpl<TransportCostMapper, TransportCost> implements TransportCostService {

    @Override
    public void add(TransportCostParam param){
        TransportCost entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(TransportCostParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(TransportCostParam param){
        TransportCost oldEntity = getOldEntity(param);
        TransportCost newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public TransportCostResult findBySpec(TransportCostParam param){
        return null;
    }

    @Override
    public List<TransportCostResult> findListBySpec(TransportCostParam param,Long operateId){
        return this.baseMapper.findListBySpec(param, operateId);
    }

    @Override
    public List<TransportCostResult> findListBySpecS(TransportCostParam param){
        return this.baseMapper.findListBySpecS(param);
    }

    @Override
    public LayuiPageInfo findPageBySpec(TransportCostParam param,String condition,Long operateId){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition,operateId);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(TransportCostParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private TransportCost getOldEntity(TransportCostParam param) {
        return this.getById(getKey(param));
    }

    private TransportCost getEntity(TransportCostParam param) {
        TransportCost entity = new TransportCost();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

	@Override
	public void deleteBySpec(TransportCostParam param) {
		this.baseMapper.deleteBySpec(param);
		
	}

}
